package com.hongyi.controller;

import com.hongyi.pojo.Pie;
import com.hongyi.pojo.Students;
import com.hongyi.result.Result;
import com.hongyi.service.StudentsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author hongyi
 * @Date 2025/4/18 11:26
 */
@RestController
@RequestMapping("/students")
public class StudentsController {
    @Resource
    StudentsService studentsService;
    @PostMapping("echart1")
    public Map<String, Object> orderList(@RequestBody Students student) {
//        List<Students> list = studentsService.lambdaQuery().eq(Students::getCity,student.getCity())
//                .eq(Students::getMajor,student.getMajor())
//                .eq(Students::getEnrollmentYear,student.getEnrollmentYear()).list();

        List<Students> list = studentsService.lambdaQuery()
                .like(Students::getCity, student.getCity()) // city 条件
                .or(i -> i.like(Students::getMajor, student.getMajor())) // major 条件
                .or(i -> i.eq(Students::getEnrollmentYear, student.getEnrollmentYear())) // enrollmentYear 条件
                .list();
        //lambda表达式
        List<Float> grades = new ArrayList<>();//接收成绩
        List<String> names = new ArrayList<>();//接收学生姓名
        System.out.println(list);
        for (Students students : list) {
            names.add(students.getName());
            grades.add(students.getScore());
        }
        //遍历
        Map<String, Object> result = new HashMap<>();
        result.put("data",grades);
        result.put("name",names);
        //hashmap返回
        return result;
    }
    @GetMapping("echart2")
    public Result<List<Pie>> Pie(){
        List<Pie> pieList = studentsService.pie();
        return Result.success(pieList);
    }
    @GetMapping("echart3")
    public Result<List<Students>> student(@RequestParam String name){
        List<Students> studentsList=studentsService.lambdaQuery().eq(Students::getName,name).list();
        return Result.success(studentsList);
    }
}
